<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <!--
        当按回车键的时候就自动聚焦到文本框
     -->
    <script>
        const inputObj = document.querySelector("input");
        document.addEventListener("keydown", function (e) {
            if (e.key === "Enter") {
                console.log("回车按键");
                inputObj.focus();
            }
        })
    </script>
</body>

</html>